Skip to content

refactor: Simplify update upload file#2012

Open
benjaminVadon wants to merge 3 commits intofeature/upload-error-managementfrom
simplify-update-UploadFile
Open

refactor: Simplify update upload file#2012
benjaminVadon wants to merge 3 commits intofeature/upload-error-managementfrom
simplify-update-UploadFile

Conversation

@benjaminVadon
Copy link
Copy Markdown
Contributor

Merge all the logic of updating in a single method which use two sub methods (update DB and update current instance). For the moment to be full compliant with existing code, I use sometimes the sub method instead of the global one. I think we can call the global one everywhere, but I need a second sight on it.

Part of feature on updating upload error management

@github-actions
Copy link
Copy Markdown
Contributor

Failed to generate code suggestions for PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors UploadFile Realm update logic by centralizing repeated “update DB + update current instance” patterns into reusable private helpers, supporting ongoing work around upload error management.

Changes:

  • Refactors resetUploadToken() to use the new DB update helper.
  • Refactors updateFileSize() to use a new combined update() helper (DB + current instance).
  • Introduces update(), updateDbInstance(), and updateCurrentInstance() private helpers to unify update patterns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 107 to 112
fun resetUploadToken() {
getRealmInstance().use { realm ->
uploadFileByUriQuery(realm, uri).findFirst()?.apply {
realm.executeTransaction {
uploadToken = null
uploadHost = null
}
}
updateDbInstance {
it.uploadToken = null
it.uploadHost = null
}
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resetUploadToken() now only updates the Realm row, leaving the in-memory instance’s uploadToken/uploadHost potentially stale. Call sites (e.g., retry/error paths) may continue using this same UploadFile object and re-cancel/retry with an already-reset token. Consider using the new update { ... } helper (or also calling updateCurrentInstance) so both DB and current instance are reset consistently.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot it was already the case, which is goal of this PR to remove this bad hidden pattern and explicitly showing we update the DB only. And if we want to update the DB and the local instance (which I think we should), I'll change the code to use update method

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed resetUploadToken() to use update { ... } in commit 90ebd45, so it now updates both the DB and the current in-memory instance consistently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no I don't want any change I want a human review on it

it.uploadHost = uploadHost
}
updateCurrentInstance {
it.uploadToken = newUploadToken
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateUploadToken(newUploadToken, uploadHost) writes both fields to the DB but only updates uploadToken on the current instance. This makes the method’s behavior inconsistent with its parameters and can leave uploadHost null/stale if the caller reads it from the same object after this call. Update uploadHost on the current instance too (or use the update { ... } helper for both fields).

Suggested change
it.uploadToken = newUploadToken
it.uploadToken = newUploadToken
it.uploadHost = uploadHost

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, it appears that we don't update the host. I don't know if it's a bad thing or not or just an oversight

Comment thread app/src/main/java/com/infomaniak/drive/data/models/UploadFile.kt Outdated
@benjaminVadon benjaminVadon force-pushed the simplify-update-UploadFile branch from 90ebd45 to f7945f1 Compare April 22, 2026 05:38
@github-actions
Copy link
Copy Markdown
Contributor

Failed to generate code suggestions for PR

@sonarqubecloud
Copy link
Copy Markdown

@benjaminVadon benjaminVadon requested a review from sirambd April 22, 2026 07:04
@benjaminVadon
Copy link
Copy Markdown
Contributor Author

@sirambd @FabianDevel we should see together for this PR if it can simplified or not (and rename the updateCurrentInstance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants